<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" indent="yes"/>
    <xsl:param name="userId">0</xsl:param>
    <xsl:param name="searchName"></xsl:param>
    <xsl:param name="sortType" select="title"></xsl:param>

    <xsl:template match="/">
        <html>
            <body>
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>

    
    <xsl:template match="feeds">
        <ul id="feed-info-list" class="clearfix">
            <xsl:if test="$sortType = 'title'">
                <xsl:for-each select="feed[contains(translate(title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), translate($searchName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))] | feed[contains(translate(decription, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), translate($searchName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))]">
                    <xsl:sort select="title"/>
                    <li>
                        <div class="rss-entry">
                            <dl class="horizon-dl">
                                <dt>Tên feed</dt>
                                <dd>
                                    <xsl:value-of select="title"/>
                                </dd>
                                <dt>Địa chỉ RSS</dt>
                                <dd>
                                    <xsl:value-of select="url"/>
                                </dd>
                                <dt>Thông tin</dt>
                                <dd>
                                    <xsl:value-of select="decription"/>
                                </dd>
                            </dl>
                            <xsl:choose>
                                <xsl:when test="userlist/userId=$userId">
                                    <div class="text-right">
                                        <a class="disabled-button">Đã có</a>
                                    </div>
                                </xsl:when>
                                <xsl:otherwise>
                                    <div class="text-right">
                                        <form action="addFeedToUserList.action" method="post">
                                            <input type="hidden" name="rssID">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select="feedId"/>
                                                </xsl:attribute>
                                            </input>
                                            <input type="hidden" name="returnTo" value="getFeedList" />
                                            <input type="submit" class="button" value="Thêm feed" />
                                        </form>
                                    </div>
                                </xsl:otherwise>
                            </xsl:choose>
                        </div>
                    </li>
                </xsl:for-each>
            </xsl:if>

            <xsl:if test="$sortType = 'addedDate'">
                <xsl:for-each select="feed[contains(translate(title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), translate($searchName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))] | feed[contains(translate(decription, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), translate($searchName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))]">
                    <xsl:sort select="addedDate" order="descending"/>
                    <li>
                        <div class="rss-entry">
                            <dl class="horizon-dl">
                                <dt>Tên feed</dt>
                                <dd>
                                    <xsl:value-of select="title"/>
                                </dd>
                                <dt>Địa chỉ RSS</dt>
                                <dd>
                                    <xsl:value-of select="url"/>
                                </dd>
                                <dt>Thông tin</dt>
                                <dd>
                                    <xsl:value-of select="decription"/>
                                </dd>
                            </dl>
                            <xsl:choose>
                                <xsl:when test="userlist/userId=$userId">
                                    <div class="text-right">
                                        <a class="disabled-button">Đã có</a>
                                    </div>
                                </xsl:when>
                                <xsl:otherwise>
                                    <div class="text-right">
                                        <form action="addFeedToUserList.action" method="post">
                                            <input type="hidden" name="rssID">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select="feedId"/>
                                                </xsl:attribute>
                                            </input>
                                            <input type="hidden" name="returnTo" value="getFeedList" />
                                            <input type="submit" class="button" value="Thêm feed" />
                                        </form>
                                    </div>
                                </xsl:otherwise>
                            </xsl:choose>

                        </div>
                    </li>
                </xsl:for-each>
            </xsl:if>

            <xsl:if test="$sortType = ''">
                <xsl:for-each select="feed[contains(translate(title, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), translate($searchName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))] | feed[contains(translate(decription, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), translate($searchName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'))]">
                    <li>
                        <div class="rss-entry">
                            <dl class="horizon-dl">
                                <dt>Tên feed</dt>
                                <dd>
                                    <xsl:value-of select="title"/>
                                </dd>
                                <dt>Địa chỉ RSS</dt>
                                <dd>
                                    <xsl:value-of select="url"/>
                                </dd>
                                <dt>Thông tin</dt>
                                <dd>
                                    <xsl:value-of select="decription"/>
                                </dd>
                            </dl>
                            <xsl:choose>
                                <xsl:when test="userlist/userId=$userId">
                                    <div class="text-right">
                                        <a class="disabled-button">Đã có</a>
                                    </div>
                                </xsl:when>
                                <xsl:otherwise>
                                    <div class="text-right">
                                        <form action="addFeedToUserList.action" method="post">
                                            <input type="hidden" name="rssID">
                                                <xsl:attribute name="value">
                                                    <xsl:value-of select="feedId"/>
                                                </xsl:attribute>
                                            </input>
                                            <input type="hidden" name="returnTo" value="getFeedList" />
                                            <input type="submit" class="button" value="Thêm feed" />
                                        </form>
                                    </div>
                                </xsl:otherwise>
                            </xsl:choose>
                        </div>
                    </li>
                </xsl:for-each>
            </xsl:if>
        </ul>
    </xsl:template>

</xsl:stylesheet>
